<?php
    @session_start();
    require_once 'shared-functions.php';
    require_once 'session.php';
    require_once 'masterpage.php';
    
    if(isset($_GET['logout']) && $_GET['logout'] == 1)
    {
        SessionCleanup();
    }

    if($_GET['page']!="")
    {
        $destination = "authenticate.php?page=".$_GET['page'];
    }
    else
    {
        $destination = "authenticate.php?page=index";
    }

    masterpage("Login");
?>
    <table>
        <tr>
            <form action="<?php echo $destination; ?>" method="post">
		<?php
		    if(isset($_SESSION['login_error']))
		    {
			    echo '<tr><td colspan="2">'.$_SESSION['login_error'].'</td></tr>';
			    $_SESSION['login_error']="";
		    }
            if(isset($_GET['error']))
            {
                echo '<tr><td colspan="2">'.$_GET['error'].'</td></tr>';
            }
		?>
            <tr><td>Username:</td><td><input type="text" name="username" size="25" /></td></tr>
            <tr><td>Password:</td><td><input type="password" name="password" size="25" /></td></tr>
            <tr class="submit"><td colspan="2"><input type="submit" value="Sign In"/></td></tr>
        <?php
            if(isset($_GET['error']))
            {
                echo '<tr><td style="font-size:60%; color: #606060; " colspan="2">Cant log in? <a href="login.php?page=index">Click here</a> then try again.</td></tr>';
            }
        ?>
        </tr>
   </table>

<?php
	endmasterpage();
?>
